package com.example.eventbus.consumor;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.Promise;
import io.vertx.core.eventbus.EventBus;
import io.vertx.core.json.JsonObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ConsumerVerticle extends AbstractVerticle {

    private static final Logger LOGGER = LoggerFactory.getLogger(ConsumerVerticle.class);

    @Override
    public void start(Promise<Void> promise) throws Exception {
        String id = config().getString("id",Thread.currentThread().getName());
        EventBus eventBus = vertx.eventBus();
        eventBus.consumer("eventbus",ar->{
            JsonObject body = (JsonObject) ar.body();
            LOGGER.info("{} receive message:{}",id,body);
        });
        promise.complete();
    }

}
